package distributedbank.gui.messages;

import distributedbank.gui.BranchGui;

/**
 * A BalanceResponse is sent by a BankBranch after receiving a Transaction
 * message from a GUI process. The BalanceResponse reports the current balance
 * of the pertinent bank account.
 */
public class BalanceResponse
        extends Response {
    public static final long serialVersionUID = 1;
    public final int balance;
    public final int transactionId;
    public final int accountId;

    public BalanceResponse(int transactionId, int branchId, int accountId,
            int balance) {
        super(transactionId, branchId);
        this.balance = balance;
        this.accountId = accountId;
        this.transactionId = transactionId;
    }

    @Override
    public void runResponse(BranchGui gui) {
        int dollars = balance / 100;
        int cents = Math.abs(balance) % 100;
        gui.println("Account " + String.format("%02d", this.branchId) + "."
                + String.format("%05d", this.accountId) + " has a balance of $"
                + dollars + "." + String.format("%02d", cents)
                + " (transaction # " + this.transactionId + ")");
        // gui.blockGUI(false);
    }
}
